package com.cloudptt.api.product.operator;

import java.util.List;

import com.cloudptt.api.product.func.SipOperator;
import com.cloudptt.api.product.func.addr.IAddrDefaultOp;
import com.mcptt.config.DbOperatorManager;
import com.mcptt.config.local.SysConfig;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.db.loader.address.MembListLoader;
import com.mcptt.db.loader.address.MembListLoaderCb;
import com.mcptt.db.loader.msg.LoginStateListLoader;
import com.mcptt.db.loader.msg.LoginStateListLoaderCb;
import com.mcptt.db.model.AddrInfo;
import com.mcptt.db.model.CameraInfo;
import com.mcptt.db.model.GroupInfo;
import com.mcptt.db.model.MapPointInfo;
import com.mcptt.db.model.UserInfo;
import com.mcptt.http.operator.IHttpAddrOpCb;
import com.mcptt.http.operator.addr.AddressLoader;
import com.mcptt.http.operator.online.OnlineLoader;

import android.content.Context;

public class AddrOperator extends SipOperator
{
//	private final static String THIS_FILE = "AddrOperator";
	//	private GroupInfo curGroupInfo = null;
	private DbOperatorManager dbOperator = null;
	private IAddrDefaultOp defaultOp = null;
	private McIdInfo mcId = null;

	public AddrOperator(Context ctx,DbOperatorManager dbOperator,IAddrDefaultOp defaultOp,McIdInfo mcId)
	{
		super(ctx);
		this.dbOperator = dbOperator;
		this.defaultOp = defaultOp;
		this.mcId = mcId;
	}

	//	public void setUid(String uid) {
	//		this.uid = uid;
	//	}
	//	public void setCurGroupInfo(GroupInfo curGroupInfo) 
	//	{
	//		this.curGroupInfo = curGroupInfo;
	//	}
	public void loadAddressAndOnline(SysConfig config,final IHttpAddrOpCb callback)
	{
		AddressLoader loader = new AddressLoader(config,dbOperator.getAddrDbOperator(),callback);
		loader.doGetAddr();
		
//		OnlineLoader loader2 = new OnlineLoader(svrIp,dbOperator.getMapDbOperator(),callback);
//		loader2.load();
	}

	public void loadAddress(SysConfig config,final IHttpAddrOpCb callback)
	{
		AddressLoader loader = new AddressLoader(config,dbOperator.getAddrDbOperator(),callback);
		loader.doGetAddr();
	}
	
	public void loadOnlineState(final String svrIp,final IHttpAddrOpCb callback)
	{
		OnlineLoader loader = new OnlineLoader(svrIp,dbOperator.getMapDbOperator(),callback);
		loader.load();
	}
	public List<GroupInfo> getGroupList()
	{
		return dbOperator.getAddrDbOperator().getGroupList();
	}

	public List<AddrInfo> getGroupAddrList()
	{
		return dbOperator.getAddrDbOperator().getGroupAddrList();
	}

	public List<GroupInfo> getGroupListAndUserList()
	{
		return dbOperator.getAddrDbOperator().getGroupListAndUserList();
	}
	public List<AddrInfo> getAddrList(String pGroupId)
	{
		return dbOperator.getAddrDbOperator().getAddrList(pGroupId);
	}
//	public void setDefaultGroupInfo(GroupInfo info)
//	{
//		AddressDbOperator db = dbOperator.getAddressDbOperator();
//		db.clearDefaultGroupInfo();
//		db.setDefaultGroupInfo(info);
//	}

	public List<UserInfo> getAddressList()
	{
		return dbOperator.getAddrDbOperator().getAddressList();
	}
	public List<AddrInfo> getUserAddrList()
	{
		return dbOperator.getAddrDbOperator().getUsrAddressList();
	}

	public List<AddrInfo> getUserAddrList(String groupMcId){
		return dbOperator.getAddrDbOperator().getUsrAddressList(groupMcId);
	}

	public List<MapPointInfo> getMapPointInfoList()
	{
		return dbOperator.getMapDbOperator().getMapPointInfoList();
	}

	public UserInfo findUserInfoByNum(int addrType,String num)
	{
		if(num == null
				|| num.length() <= 0)
		{
			return null;
		}
		UserInfo info = dbOperator.getAddrDbOperator().findUserByNum(addrType,num);
		return info;
	}

	//	public void deleteUser(UserInfo info)
	//	{
	//		dbOperator.getAddressDbOperator().deleteUser(info);
	//	}

	//	private void addUser(UserInfo info)
	//	{
	//		dbOperator.getAddressDbOperator().addUser(info);
	//	}

	//	public AddressListLoader getAddressListLoader(Context ctx,int addrType,AddressListLoaderCb callback)
	//	{
	//		return new AddressListLoader(ctx,addrType,callback);
	//	}

	public List<UserInfo> getNewAddressList(String groupMcId){
		return dbOperator.getAddrDbOperator().getNewAddressList(groupMcId);
	}
	
	public List<UserInfo> getNewAddressList(String groupMcId,String mcId){
		return dbOperator.getAddrDbOperator().getNewAddressList(groupMcId,mcId);
	}

	public LoginStateListLoader getLoginStateListLoader(Context ctx, LoginStateListLoaderCb callback){
		return new LoginStateListLoader(ctx,this, callback);
	}

	public MembListLoader getMembListLoader(Context ctx,UserInfo info,MembListLoaderCb callback)
	{
		return new MembListLoader(ctx,info,callback);
	}

//	public boolean isGrpHasMem(String uid)
//	{
//		return dbOperator.getGroupMembsDbOperator().isGrpHasMem(uid);
//	}


	//	public void sendGroupMembInfoMsg() throws RemoteException
	//	{
	//		Log.d(THIS_FILE, "sendGroupMembInfoMsg");
	//		if( curGroupInfo != null)
	//		{
	//			Log.d(THIS_FILE, "sendGroupMembInfoMsg curGroupInfo = " + curGroupInfo);
	//			sendGroupMembInfoMsg(curGroupInfo);
	//		}
	//	}
	//
	//	public void sendGroupMembStatusMsg(int opType) throws RemoteException
	//	{
	//		Log.d(THIS_FILE, "sendGroupMembStatusMsg opType = " + opType);
	//		if( curGroupInfo != null)
	//		{
	//			Log.d(THIS_FILE, "sendGroupMembStatusMsg curGroupInfo = " + curGroupInfo + " opType = " + opType);
	//			sendGroupMembStatusMsg(curGroupInfo,opType);
	//		}
	//		
	////		if(opType == GroupMembInfo.QueryMembStatus_Begin)
	////		{
	////			dbOperator.getGroupMembsDbOperator().resetGrpMemCallState();
	////		}
	//		
	//		dbOperator.getGroupMembsDbOperator().resetGrpMemCallState();
	//	}

	public void resetGrpMemCallState()
	{
		dbOperator.getGroupMembsDbOperator().resetGrpMemCallState();
	}
	
	public List<CameraInfo> getCameraList()
	{
		return dbOperator.getCameraDbOperator().getCameraList();
	}
	
	public void addCameraInfo(CameraInfo info)
	{
		dbOperator.getCameraDbOperator().addCameraInfo(info);
	}
	
	public CameraInfo findCameraInfoByIp(String ip)
	{
		return dbOperator.getCameraDbOperator().findCameraInfoByIp(ip);
	}
	
	public void deleteCameraInfo(CameraInfo info)
	{
		dbOperator.getCameraDbOperator().deleteCameraInfo(info);
	}
}
